home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 43 / Amiga Format CD43 (1999)(Future Publishing)(GB)(Track 1 of 2)[!][issue 1999-09].iso / -serious- / programming / arexx / rexxbgui / dirlist.rexx < prev    next >
OS/2 REXX Batch file  |  1999-06-14  |  4KB  |  155 lines

  1. /* REXX script for rexxbgui.library: directory listing in listview */
  2.  
  3. if ~show('l','rexxbgui.library') then do
  4.     if ~addlib('rexxbgui.library',0,-30) then do
  5.         exit(20)
  6.     end
  7.     else nop
  8. end
  9. else nop
  10.  
  11. if ~show('l','rexxsupport.library') then do
  12.     if ~addlib('rexxsupport.library',0,-30) then do
  13.         exit(20)
  14.     end
  15.     else nop
  16. end
  17. else nop
  18.  
  19. call bguiopen() /* causes error 12 if it did not work */
  20. /* supply a second argument for a '0' return code instead of an ARexx
  21.    error */
  22.  
  23. signal on syntax /* important: bguiclose() MUST be called */
  24. signal on halt
  25. signal on break_c
  26.  
  27. esc='1B'x
  28. lf='0A'x
  29. cr='0D'x
  30. grspace.narrow=-1
  31. grspace.normal=-2
  32. grspace.wide=-3
  33.  
  34. olddir=pragma('d',arg(1))
  35. dir=pragma('d',olddir)
  36.  
  37. /* using ARexx feature: ,<newline> is translated to nothing */
  38. /* the || are essential - any added space will cause trouble */
  39. /* redefining the same ID makes previous buttons unaccessible */
  40. /* do not redefine winclose etc. */
  41.  
  42. g=bguivgroup(,
  43.     bguivgroup(,
  44.         bguistring('str',,dir,256)||bguilayout(LGO_FixMinHeight,1)||,
  45.         bguilistview('listv')||,
  46.         bguihgroup(,
  47.             bguibutton('parent','_Parent')||,
  48.             bguibutton('root','_Root'),
  49.         ,0,,,'W')||bguilayout(LGO_FixMinHeight,1),
  50.     ,0)||,
  51.     bguihgroup(,
  52.         bguivarspace(50)||,
  53.         bguibutton('quit','_Quit')||,
  54.         bguivarspace(50),
  55.     )||bguilayout(LGO_FixMinHeight,1),
  56. ,grspace.normal,grspace.normal)
  57.  
  58. a=bguiwindow('Directory listing in listview',g,40,70)
  59.  
  60. if bguiwinopen(a)=0 then bguierror(12)
  61.  
  62. text='cbDirectory listing in listview-b'lf||lf||,
  63.     'This ARexx script shows a directory listing in a'lf||,
  64.     'listview. Because of the bad design of'lf||,
  65.     'rexxsyslib.library/SHOWDIR() the directory has to be'lf||,
  66.     'read twice to distinguish directories and files.'lf||,
  67.     'For the same reason only the filename is shown'lf||,
  68.     'and not the size and similar information'lf||lf||,
  69.     'Be warned that reading large directories is slow.'lf||lf||,
  70.     'The first directory to be listed is:'lf||,
  71.     'b'||dir
  72. if bguireq(text,'*_Continue|_Quit',,a)=0 then do
  73.     rc=0; signal syntax
  74. end; else nop
  75. drop text
  76.  
  77. call readdir(dir)
  78.  
  79. id=0
  80. do while bguiwinwaitevent(a,'ID')~=id.winclose
  81.     select
  82.         when id=id.str then do
  83.             dir=bguiget(obj.str,STRINGA_TextVal)
  84.             call readdir(dir)
  85.         end
  86.         when id=id.listv then do
  87.             e=bguiget(obj.listv,LISTV_LastClicked)
  88.             if left(e,3)='d8' then do
  89.                 if right(dir,1)~=':' & right(dir,1)~='/' then do
  90.                     dir=dir'/'
  91.                 end; else nop
  92.                 dir=dir||substr(e,6)
  93.                 bguiset(obj.str,a,STRINGA_TextVal,dir)
  94.                 call readdir(dir)
  95.             end; else nop
  96.         end
  97.         when id=id.parent then do
  98.             prevdir=dir
  99.             olddir=pragma('d',dir)
  100.             call pragma('d','/')
  101.             dir=pragma('d',olddir)
  102.             if prevdir~=dir then do
  103.                 bguiset(obj.str,a,STRINGA_TextVal,dir)
  104.                 call readdir(dir)
  105.             end; else call bguireq('Can''t get parent!','*_OK',,a)
  106.         end
  107.         when id=id.root then do
  108.             prevdir=dir
  109.             olddir=pragma('d',dir)
  110.             call pragma('d',':')
  111.             dir=pragma('d',olddir)
  112.             if prevdir~=dir then do
  113.                 bguiset(obj.str,a,STRINGA_TextVal,dir)
  114.                 call readdir(dir)
  115.             end; else nop
  116.         end
  117.         when id=id.sort then call bguilistvcommand(obj.listv,a,'sort')
  118.         when id=id.winactive then nop
  119.         when id=id.wininactive then nop
  120.         when id=id.quit then leave
  121.         when id=id.winclose then nop
  122.         otherwise nop
  123.     end
  124. end
  125. rc=0
  126.  
  127. syntax:
  128. if rc~=0 then say '+++ ['rc']' errortext(rc) 'at line' sigl
  129. call bguiclose()
  130. exit 0
  131.  
  132. break_c:
  133. halt:
  134. rc=0
  135. say '+++ Break at line' sigl
  136. signal syntax
  137.  
  138. readdir:
  139. parse arg dir
  140. call bguiwinbusy(a)
  141. call bguilistvcommand(obj.listv,a,'clear')
  142. lst=showdir(dir,'D','/')
  143. do while lst~=''
  144.     parse var lst entry '/' lst
  145.     call bguilistvaddentry(obj.listv,,'d8'entry,'S')
  146. end
  147. lst=showdir(dir,'F','/')
  148. do while lst~=''
  149.     parse var lst entry '/' lst
  150.     call bguilistvaddentry(obj.listv,,entry,'S')
  151. end
  152. call bguilistvcommand(obj.listv,a,'refresh')
  153. call bguiwinready(a)
  154. return 1
  155.